﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using ProcessRoll.Utilities;
using ProcessRoll.Models;
using System.Data.Entity;

namespace ProcessRoll
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "ProcessRoll", action = "index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            
            CH.AddMapping(typeof(Process), typeof(DB), "ID");
            CH.AddMapping(typeof(Field), typeof(DB), "ID");
            CH.AddMapping(typeof(Company), typeof(DB), "ID");
            CH.AddMapping(typeof(Condition), typeof(DB), "ID");
            CH.AddMapping(typeof(Activity), typeof(DB), "ID");
            CH.AddMapping(typeof(Department), typeof(DB), "ID");
            CH.AddMapping(typeof(Receiver), typeof(DB), "ID");
            CH.AddMapping(typeof(Role), typeof(DB), "ID");
            CH.AddMapping(typeof(Queue), typeof(DB), "ID");
            CH.AddMapping(typeof(Container), typeof(DB), "ID");
            CH.AddMapping(typeof(NodeData), typeof(DB), "ID");
            //CH.AddMapping(typeof(DepartmentEmployee), typeof(DB), "ID");
            CH.AddMapping(typeof(Employee), typeof(DB), "ID");
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
            //Database.SetInitializer<DB>(new ProcessInitializer());
            var es = CH.GetAllData<Employee>();
        }
    }
}